--默认游戏桌子界面

local RoomLayer = class("RoomLayer", function(scene)
		local roomLayer =  display.newLayer()
    return roomLayer
end)
local HeadSprite = appdf.req(appdf.EXTERNAL_SRC .. "HeadSprite")
local ExternalFun = appdf.req(appdf.EXTERNAL_SRC .. "ExternalFun")
RoomLayer.BT_FIND = 1
RoomLayer.BT_LOCK = 2
function RoomLayer:ctor(scene, bQuickStart,gameinfo)
	self.typeLayer,typeCsbNode =  ExternalFun.loadRootCSB( "plaza/typeLayer.csb", self)

	self.three_Panel = typeCsbNode:getChildByName("three_Panel")
	self.two_Panel = typeCsbNode:getChildByName("two_Panel")
	self.two_Panel:setVisible(false)
	self.three_Panel:setVisible(true)
	self.gameinfo = gameinfo 

	self.selectGameKindId = checkint(gameinfo.gameid)
	self.selectGameVersion=gameinfo.version
	self.three_Panel:setDirection(cc.SCROLLVIEW_DIRECTION_NONE)

	local size = self.three_Panel:getContentSize()


	
   local data = gameinfo.roomls or {}
   self.gamedata = data
   local cnode = self.three_Panel:getItem(0):clone()
   self.three_Panel:removeItem(0)
   local addlen = 0
   for i=1,4 do
		if data[i] then
			local detail = data[i]
			-- dump(data[i+1],"data.wServerLevel")
			addlen = addlen + 1
			local node = cnode:clone()
			node:setTag(i)
			node:addTouchEventListener(handler(self,self.ThreePanelCB))
			node:setContentSize(display.width/4-5,500)
			node:setVisible(true)
			self.three_Panel:pushBackCustomItem(node)
		end	
   end


  
end

function RoomLayer:ThreePanelCB(pSender,type)
     if type == ccui.TouchEventType.ended then
		 local wServerLevel = pSender:getTag()
		--  local gameinfo = GlobalUserItem.roomkindlist[checkint(self.selectGameKindId)]
		 local data = self.gamedata[wServerLevel]
		 data.gameid = self.gameinfo.gameid
		 GlobalUserItem.nCurCGameId = data.roomid
		 self:onEnterGame( data ,true)
     end
end

function RoomLayer:onEnterGame( gamedata, isQuickStart)
	-- dump(gameinfo,"onEnterGame >>>  gameinfo")
	self:updateEnterGameInfo(gamedata)
	self.m_bQuickStart = isQuickStart
	
	GlobalUserItem.nCurRoomIndex = gamedata.level or 1
	GlobalUserItem.nCurGameKind = gamedata.roomid
	self:getParent():getParent().retryTime = 0
	self:getParent():getParent():onStartGame()
	self:getParent():getParent():showPopWait()
end

--更新游戏进入记录
function RoomLayer:updateEnterGameInfo(info)
	self:getRootNode():updateEnterGameInfo(info)
end

--获取父场景节点(ClientScene)
function RoomLayer:getRootNode( )
	return self:getParent():getParent()
end

return RoomLayer